# VHost config for {{ app_name }}
{% for item in salt['pillar.get']('vhost:' + app_name, {}) %}
server {
    listen 80;
    server_name "~{{ item["host_header"] }}";

    root {{ item["document_root"] }};
    index index.php index.html index.htm;

    location / {
      try_files $uri $uri/ /index.php$is_args$args;
    }

	{% if "rewrite_rule" in item %}
    {% for rewrite_rule in item["rewrite_rule"] -%}
	rewrite {{ rewrite_rule["regex"] }} {{ rewrite_rule["replacement"] }} break;
    {% endfor -%}
    {% endif %}

    location ~ \.php {
      fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include /etc/nginx/fastcgi_params;
    }
}
{% endfor %}
